package com.le.dub.common;

import cn.hutool.core.util.ReflectUtil;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 集合工具类
 * @author zhengxiangyu
 */
public class ListUtils {



    /**
     * 复制
     * @param list
     * @param clazz
     * @param <T>
     * @param <R>
     * @return
     */
    public static <T, R> List<T> copy(List<R> list, Class<T> clazz){
        return list.stream().map(x -> {
            T obj = ReflectUtil.newInstance(clazz);
            BeanUtils.copyProperties(x, obj);

            return obj;
        }).collect(Collectors.toList());
    }

}
